package rpc.frame.client.proxy;

import lombok.extern.slf4j.Slf4j;
import net.sf.cglib.proxy.Enhancer;
import org.springframework.stereotype.Component;
import rpc.frame.core.proxy.ProxyFactory;

/**
 * 动态代理
 */
@Slf4j
@Component
public class RequestProxyFactory implements ProxyFactory {
    @Override
    public <T> T newProxyInstance(Class<T> cls) {
        Enhancer enhancer = new Enhancer();
        enhancer.setSuperclass(cls);
        enhancer.setCallback(new CglibProxyCallBackHandler());
        return (T) enhancer.create();
    }
}
